<!-- 提货专区首页 -->
<template>
	<view class="container">
		<uni-nav-bar statusBar="true" fixed="true" @clickLeft="goBack" title="VIP提货专区" color="#333333" leftIcon="back" :background="navBg"></uni-nav-bar>
		<view class="header">
			<view class="searchBox">
				<view class="search">
					<icon class="searchIcon" type="search" :size='20' color='#999'></icon>
					<input class="searchInp" type="text" confirm-type="search" v-model="keyword" placeholder="请输入商品名称" @confirm="search" />
				</view>
				<view class="cart" @tap="navTo('/mall/pickCardMall/pickCardCart')">
					<image class="cartIcon" src="../static/images/tubiao.png" mode=""></image>
				</view>
			</view>
			<view class="cateBox">
				<view class="cateList">
					<scroll-view class="scroll__view" scroll-x="true">
						<view class="list">
							<block>
								<view class="item" @click="clickCate(0,0)">
									<view :class="active === 0?'active':''" class="item-text">
										推荐
										<view class="activeBg" v-if="active === 0">
											<view class="a"></view>
											<view class="b"></view>
										</view>
									</view>
								</view>
							</block>
							<block v-for="(item,index) in cate_list" :key="index">
								<view class="item" @click="clickCate(index + 1,item.id)">
									<view :class="active === index+1?'active':''" class="item-text">
										{{item.cate_name}}
										<view class="activeBg" v-if="active === index + 1">
											<view class="a"></view>
											<view class="b"></view>
										</view>
									</view>
								</view>
							</block>
							<block>
								<view class="item cut">
									<view class="item-text">
										1
									</view>
								</view>
							</block>
						</view>
					</scroll-view>
				</view>
				<view class="cate" @tap="navTo('/mall/pickCardMall/pickCardCate')">
					<image src="../static/images/1dsfsb.png" mode=""></image>
					<text>分类</text>
				</view>
			</view>
		</view>
		<view class="headerCut" v-show="active == 0"></view>
		<!-- 轮播 -->
		<view class="carousel-section" v-show="active == 0">
			<swiper class="carousel" circular autoplay :indicator-dots="true" indicator-color="rgba(255,255,255,.5)"
			 indicator-active-color="#ffffff">
				<swiper-item v-for="(item, index) in data.banner" :key="index" class="carousel-item" @click="navTo(item.link)">
					<image class="carousel-image" lazy-load :src="item.img" />
				</swiper-item>
			</swiper>
		</view>
		<!-- 分类 -->
		<view class="secendCate" v-if="sub_category.length">
			<view class="item" v-if="index < 9" v-for="(item,index) in sub_category" :key="index" @tap="navTo('/mall/pickCardMall/pickCardList?id=' + item.id)">
				<image :src="item.pic" mode=""></image>
				<text class="label">{{item.cate_name}}</text>
			</view>
			<view class="item" @tap="navTo('/mall/pickCardMall/pickCardCate?cateId=' + cate_list[active-1].id)">
				<view class="more">
					<text>查看更多</text>
					<view class="line"></view>
					<text>see more</text>
				</view>
				<text class="label">更多分类</text>
			</view>
		</view>
		<!-- 二级轮播 -->
		<view class="sub_banner" v-if="sub_banner.length">
			<swiper class="carousel" circular autoplay :indicator-dots="true" indicator-color="rgba(255,255,255,.5)"
			 indicator-active-color="#ffffff">
				<swiper-item v-for="(item, index) in sub_banner" :key="index" class="carousel-item">
					<image class="carousel-image" lazy-load :src="item" />
				</swiper-item>
			</swiper>
		</view>
		<view class="goods-list">
			<view class="cardInfoMin" @tap="!cardInfo.card_value&&goVip()">
				<text class="a">{{cardInfo.name||''}}</text>
				<view class="b">
					<text class="b-a" v-if="cardInfo.card_value">{{cardInfo.card_value||''}}</text>
					<text class="b-a no" v-else>提货卡</text>
					<text class="b-b yticon icon-you" v-if="!cardInfo.card_value"></text>
				</view>
			</view>
			<empty v-if="empty" :custom="true" src="/mall/static/images/no-goods.png" text="无相关商品"></empty>
			<goods-block :goodsList="goodsList" :pick="true" :scrollTop="scrollTop"></goods-block>
			<uni-load-more class="loadMore" iconType="circle" :status="loadStatus" :contentText="contentText"></uni-load-more>
		</view>

	</view>
</template>

<script>
	import empty from "@/components/empty/empty";
	import utils from "@/common/utils.js"
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import goodsBlock from "@/components/goodsBlock/goodsBlock.vue"
	import {
		takeProducts,
		takeproductsindex,
		takeCategory,
	} from '@/api/mall.js'
	import {
		deliveryCard
	} from '@/api/user.js'
	export default {
		components: {
			uniLoadMore,
			goodsBlock,
			empty
		},
		data() {
			return {
				navBg: "linear-gradient(90deg, #DFCF93 0%, #F2E9C7 100%)",
				type: 0, //是否从商城首页跳转 是/1 否/0
				cardId: 0, //提货卡Id
				active: 0, //商品分类选中索引
				data: {}, //初始数据
				cate_list: [], //分类数据
				sub_category: [], //二级分类
				sub_banner: [], //二级分类
				cardInfo: {
					name: ""
				}, //提货卡信息
				empty: false, //商品列表是否为空
				countdown_time: "00:00:00", //提货卡倒计时
				//翻页参数
				page: 1,
				limit: 10,
				loadStatus: "loading",
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多了"
				},
				keyword: '', //搜索关键词
				cid: 0, //分类id
				goodsList: [], //商品列表数据
				scrollTop:0
			}
		},
		onLoad(option) {
			if (option.id) {
				this.cardId = option.id
				this.type = 0
			} else {
				this.type = 1
			}
			uni.setStorageSync("cardId",this.cardId)
			takeproductsindex().then(res => {
				this.data = res.data
			})
			takeCategory().then(res => {
				this.cate_list = res.data
			})
			this.loadData()
		},
		onShow() {
			deliveryCard({
				type: this.type,
				card_id: uni.getStorageSync("cardId"),
				order_id: uni.getStorageSync("card_order_id")||''
			}).then(res => {
				if (res.data.cardInfo.name) {
					this.cardInfo = res.data.cardInfo
					this.cardInfo.card_value = utils.format(this.cardInfo.card_value)
				} else {
					this.cardInfo.name = "前往购买"
				}
			})
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		//加载更多
		onReachBottom() {
			if (this.loadStatus == "more")
				(this.loadStatus = "loading"), this.loadData();
		},
		methods: {
			loadData() {
				takeProducts({
					page: this.page,
					limit: this.limit,
					keyword: this.keyword,
					cid: this.cid
				}).then(res => {
					this.loadStatus = "more";
					this.goodsList.push.apply(this.goodsList, res.data.goodsList);
					if (res.data.goodsList.length < this.limit) this.loadStatus = "noMore"; //判断所有数据是否加载完成；
					this.page = this.page + 1;
					if (this.goodsList.length == 0) {
						this.empty = true
						this.contentText.contentnomore = ''
					} else {
						this.contentText.contentnomore = '没有更多了'
					}
				})
			},
			goBack() {
				uni.navigateBack({
					
				})
			},
			search() {
				uni.navigateTo({
					url: "./pickCardList?keyword=" + this.keyword + "&cardId=" + this.cardId
				})
			},
			clickCate(index, id) {
				this.active = index
				this.cid = id
				this.loadStatus = "loading";
				this.page = 1;
				if (index !== 0) {
					this.sub_category = this.cate_list[index - 1].sub_category
					this.sub_banner = this.cate_list[index - 1].banner
				} else {
					this.sub_category = []
					this.sub_banner = []
				}
				this.goodsList = [];
				this.empty = false
				this.loadData()
			},
			goVip() {
				if (uni.getStorageSync("userInfo")) {
					uni.navigateTo({
						url: "/pages/center/vip/vipRights"
					})
				} else {
					uni.navigateTo({
						url: "/pages/login/login"
					})
				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.container {
		.header {
			position: sticky;
			//#ifdef APP-PLUS
			top: calc(var(--status-bar-height) + 44px);
			//#endif
			//#ifdef H5
			top: 44px;
			//#endif
			left: 0;
			background: linear-gradient(90deg, #DFCF93 0%, #F2E9C7 100%);
			z-index: 9;

			.searchBox {
				position: relative;
				padding: 20rpx 30rpx;
				z-index: 3;
				display: flex;
				justify-content: space-between;

				.search {
					position: relative;

					.searchIcon {
						position: absolute;
						left: 20rpx;
						top: 18rpx;
					}

					.searchInp {
						width: 620rpx;
						height: 72rpx;
						padding-left: 80rpx;
						font-size: 28rpx;
						box-sizing: border-box;
						background: #FAF9F3;
						border-radius: 36rpx;
					}
				}

				.cart {
					margin-top: 16rpx;
					.cartIcon {
						width: 45rpx;
						height: 40rpx;
					}
				}
			}

			.cateBox {
				position: relative;
				z-index: 3;

				.cate {
					position: absolute;
					right: 0;
					top: 0;
					padding: 0 30rpx;
					color: #333;
					font-weight: bold;
					background: linear-gradient(90deg, #EFE4BE 0%, #F2E8C6 100%);
					box-shadow: -10rpx 0 10rpx #EFE4BE;
					height: 90rpx;
					line-height: 96rpx;
					display: flex;
					align-items: center;

					image {
						width: 50rpx;
						height: 50rpx;
					}
				}

				.cateList {
					.scroll__view {
						width: 100%;
					}

					.list {
						display: flex;
						align-items: baseline;

						.item {
							padding: 0 30rpx;
							white-space: nowrap;
							font-size: 24rpx;
							line-height: 90rpx;
							color: #333;
							font-size: 32rpx;
							text-align: center;

							.item-text {
								min-width: 80rpx;
							}

							.active {
								color: #333;
								font-size: 40rpx;
								font-weight: bold;
								position: relative;

								.activeBg {
									width: 100%;
									height: 80rpx;
									position: absolute;
									left: 0;
									top: 0;

									.a {
										position: absolute;
										left: -6rpx;
										top: 10rpx;
										width: 23rpx;
										height: 23rpx;
										background: linear-gradient(90deg, rgba(87, 190, 106, 1) 0%, rgba(87, 190, 106, 0.01) 99%);
										opacity: 0.59;
										border-radius: 50%;
									}

									.b {
										position: absolute;
										right: -10rpx;
										bottom: 6rpx;
										width: 42rpx;
										height: 42rpx;
										background: linear-gradient(0deg, rgba(255, 168, 0, 1) 0%, rgba(255, 168, 0, 0) 100%);
										opacity: 0.38;
										border-radius: 50%;
									}
								}
							}
						}

						.cut {
							min-width: 140rpx;
							opacity: 0;
						}
					}
				}
			}
		}

		.headerCut {
			height: 100rpx;
			width: 100%;
			background: linear-gradient(90deg, #DFCF93 0%, #F2E9C7 100%);
		}

		/* 轮播 */
		.carousel-section {
			position: relative;
			z-index: 2;
			margin-top: -82rpx;
			padding: 0 15px;

			.carousel {
				background-color: #fafafa;
				width: 100%;
				border-radius: 30rpx;
				box-sizing: border-box;
				overflow: hidden;
				height: 260rpx;

				.carousel-item {
					width: 100%;
					height: 100%;
					// padding: 0 28rpx;
					overflow: hidden;
				}

				.carousel-image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.secendCate {
			margin: 20rpx auto;
			width: 690rpx;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 20rpx 25rpx;
			box-sizing: border-box;
			display: flex;
			flex-wrap: wrap;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 8rpx 5rpx;

				image {
					width: 120rpx;
					height: 120rpx;
					border-radius: 8rpx;
				}

				.label {
					margin-top: 6rpx;
					font-size: 24rpx;
					color: #333333;
				}
			}

			.more {
				background: #efefef;
				width: 120rpx;
				height: 120rpx;
				border-radius: 8rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				text {
					font-size: 24rpx;
					color: #bbb;
				}

				.line {
					margin-top: 4rpx;
					width: 110rpx;
					height: 1rpx;
					background: #ddd;
				}
			}
		}

		.goods-list {
			padding: 14rpx 30rpx;

			.cardInfoMin {
				position: fixed;
				left: 0;
				bottom: 300rpx;
				padding: 0rpx 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				height: 90rpx;
				background: #FFF9E2;
				border-radius: 0px 8rpx 8rpx 0px;
				z-index: 99;

				.a {
					font-size: 20rpx;
					font-weight: 500;
					color: rgba(51, 51, 51, 1);
				}

				.b {
					display: flex;
					align-items: center;

					.b-a {
						font-size: 24rpx;
						font-weight: bold;
						color: #FAD03C;
					}

					.b-b {
						margin-left: 4rpx;
						width: 20rpx;
						height: 20rpx;
						line-height: 20rpx;
						text-align: center;
						background: #FEC93B;
						border-radius: 50%;
						color: #fff;
						font-size: 14rpx;
					}

					.no {
						font-size: 20rpx;
						font-weight: normal;
						color: rgba(51, 51, 51, 1);
					}

				}
			}
		}

		.sub_banner {
			position: relative;
			z-index: 2;
			padding: 0 15px;

			.carousel {
				background-color: #fafafa;
				width: 100%;
				border-radius: 30rpx;
				box-sizing: border-box;
				overflow: hidden;
				height: 160rpx;

				.carousel-item {
					width: 100%;
					height: 100%;
					// padding: 0 28rpx;
					overflow: hidden;
				}

				.carousel-image {
					width: 100%;
					height: 100%;
				}
			}
		}


	}

	/deep/.empty-content {
		top: 500rpx !important;
	}
</style>
